package com.javasm.transfer.orderTransfer;

import com.javasm.domin.entity.goodsEntity.GdBrand;
import com.javasm.domin.entity.goodsEntity.GdColour;
import com.javasm.domin.entity.goodsEntity.GdGoods;
import com.javasm.domin.entity.goodsEntity.GdType;
import com.javasm.domin.entity.orderEntity.B2cOrderGoods;
import com.javasm.domin.vo.orderVo.OrderGoodVo;
import com.javasm.mapper.B2cOrderMapper.OrderGoodsMapper;
import com.javasm.mapper.goodsMapper.GdBrandMapper;
import com.javasm.mapper.goodsMapper.GdColourMapper;
import com.javasm.mapper.goodsMapper.GdGoodsMapper;
import com.javasm.mapper.goodsMapper.GdTypeMapper;
import com.javasm.transfer.base.BaseTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/11/21-19:45
 * @Since:jdk1.8
 * @Description:
 */

@Component

public class OrderGoodsTransfer extends BaseTransfer<B2cOrderGoods, OrderGoodVo> {
    private  OrderGoodsMapper orderGoodsMapper;
    @Resource
    private  GdGoodsMapper goodsMapper;
    @Resource
    private  GdBrandMapper gdBrandMapper;
    @Resource
    private  GdColourMapper gdColourMapper;
    @Resource
    private  GdTypeMapper gdTypeMapper;


    public List<OrderGoodVo> setString(List<B2cOrderGoods> b2cOrderGoodsList) {
        //将B2cOrderGoods转成orderGoodVo
        List<OrderGoodVo> orderGoodVoList = super.toVO(b2cOrderGoodsList);

        for (int i = 0; i < orderGoodVoList.size(); i++) {
            B2cOrderGoods b2cOrderGoods = b2cOrderGoodsList.get(i);
            System.out.println(b2cOrderGoods.getGoodsId());
            //根据商品id得到商品对象
            String goodsId = b2cOrderGoods.getGoodsId();
            GdGoods gdGoods = goodsMapper.selectById(goodsId);
            //根据品牌id得到对象
            Integer brandId = b2cOrderGoods.getBrandId();
            GdBrand gdBrand = gdBrandMapper.selectById(brandId);
            //根据颜色id得到颜色
            Integer colorId = b2cOrderGoods.getColorId();
            GdColour gdColour = gdColourMapper.selectById(colorId);
            //根据类型id得到类型
            Integer typeId = b2cOrderGoods.getTypeId();
            GdType gdType = gdTypeMapper.selectById(typeId);
            //转义赋值
            OrderGoodVo orderGoodVo = orderGoodVoList.get(i);
            orderGoodVo.setOrderProductName(gdGoods == null ? "" : gdGoods.getGoodsName());
            orderGoodVo.setBrandId(gdBrand == null ? "" : gdBrand.getBrandName());
            orderGoodVo.setColorId(gdColour == null ? "" : gdColour.getColourName());
            orderGoodVo.setTypeId(gdType == null ? "" : gdType.getTypeName());
        }
        return orderGoodVoList;
    }
}
